package com.ser03;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo1")
public class ServletDemo1 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //设置域内容
        request.setAttribute("name", "tom");

        //获取
        Object name = request.getAttribute("name");
        System.out.println(name);
        System.out.println("-------------------");

        //删除
        request.removeAttribute("name");
        Object name1 = request.getAttribute("name");
        System.out.println(name1);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
